package gov.pbc.nn.kjgl.fxq.attachment;

import java.util.Collection;
import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Order;
import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Component;

import com.bstek.dorado.annotation.DataProvider;

import gov.pbc.nn.core.dao.CommonHibernateDao;

@Component(AttachmentDao.BEAN_ID)
public class AttachmentDao extends CommonHibernateDao {
	public static final String BEAN_ID = "attachmentDao";
	
	@DataProvider
	public Collection<AttachmentEntity> getAttachmentsByfxqEntityId(String fxqEntityId) throws Exception {
		DetachedCriteria detachedCriteria=DetachedCriteria.forClass(AttachmentEntity.class);
		detachedCriteria.add(Restrictions.eq("invalid",false));
		detachedCriteria.add(Restrictions.eq("fxqEntityId", fxqEntityId));
		detachedCriteria.addOrder(Order.desc("createDate"));
		return (Collection<AttachmentEntity>) this.query(detachedCriteria);
	}
}
